/* USER CODE BEGIN Header */
/**
  ******************************************************************************
  * @file           : main.c
  * @brief          : Main program body
  ******************************************************************************
  * @attention
  *
  * <h2><center>&copy; Copyright (c) 2019 STMicroelectronics.
  * All rights reserved.</center></h2>
  *
  * This software component is licensed by ST under BSD 3-Clause license,
  * the "License"; You may not use this file except in compliance with the
  * License. You may obtain a copy of the License at:
  *                        opensource.org/licenses/BSD-3-Clause
  *
  ******************************************************************************
  */
/* USER CODE END Header */

/* Includes ------------------------------------------------------------------*/
#include "main.h"

/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */
#include "ssd2828.h"
//#include "R69434.h"
//#include "ST7796S__PH035NA_01B.h"
#include "ST7703__BV055HDE_N47_3Q00.h"

/* USER CODE END Includes */

/* Private typedef -----------------------------------------------------------*/
/* USER CODE BEGIN PTD */

/* USER CODE END PTD */

/* Private define ------------------------------------------------------------*/
/* USER CODE BEGIN PD */
/* USER CODE END PD */

/* Private macro -------------------------------------------------------------*/
/* USER CODE BEGIN PM */

/* USER CODE END PM */

/* Private variables ---------------------------------------------------------*/
UART_HandleTypeDef huart1;

/* USER CODE BEGIN PV */

/* USER CODE END PV */

/* Private function prototypes -----------------------------------------------*/
void SystemClock_Config(void);
static void MX_GPIO_Init(void);
static void MX_USART1_UART_Init(void);
static void MX_NVIC_Init(void);
/* USER CODE BEGIN PFP */

/* USER CODE END PFP */

/* Private user code ---------------------------------------------------------*/
/* USER CODE BEGIN 0 */

int _write(int file, char *ptr, int len)
{
  switch (file)
  {
  case STDOUT_FILENO: //stdout
    HAL_UART_Transmit(&huart1, (uint8_t *)ptr, len, 0xff);
    break;
  case STDERR_FILENO: // stderr
    // Send the string somewhere
    break;
  default:
    return -1;
  }
  return len;
}

void init(void)
{
  //SSD2828_Initial
  W_C(0xb7);
  W_D(0x50); //50=TX_CLK 70=PCLK
  W_D(0x00); //Configuration Register

  W_C(0xb8);
  W_D(0x00);
  W_D(0x00); //VC(Virtual ChannelID) Control Register

  W_C(0xb9);
  W_D(0x00); //1=PLL disable
  W_D(0x00);
  //TX_CLK/MS should be between 5Mhz to100Mhz
  W_C(0xBA); //PLL=(TX_CLK/MS)*NS 8228=480M 4428=240M  061E=120M 4214=240M 821E=360M 8219=300M
  W_D(0x14); //D7-0=NS(0x01 : NS=1)
  W_D(0x42); //D15-14=PLL范围 00=62.5-125 01=126-250 10=251-500 11=501-1000  DB12-8=MS(01:MS=1)

  W_C(0xBB); //LP Clock Divider LP clock = 400MHz / LPD / 8 = 240 / 8 / 4 = 7.5MHz
  W_D(0x03); //D5-0=LPD=0x1 – Divide by 2
  W_D(0x00);

  W_C(0xb9);
  W_D(0x01); //1=PLL disable
  W_D(0x00);
  //MIPI lane configuration
  W_C(0xDE); //通道数
  W_D(0x01); //11=4LANE 10=3LANE 01=2LANE 00=1LANE
  W_D(0x00);

  W_C(0xc9);
  W_D(0x02);
  W_D(0x23); //p1: HS-Data-zero  p2: HS-Data- prepare  --> 8031 issue
  delay_ms(100);

  /*============================================================================*/

  //LCD driver initialization
  W_C(0xB7);
  W_D(0x10); //10=TX_CLK 30=PCLK
  W_D(0x02);

  W_C(0xBD);
  W_D(0x00);
  W_D(0x00);

  /*============================================================================*/
  /*==========================================LCD INITIAL========================================================================*/

  /**************************************************
IC);W_D(Name:);W_D(RM68200GA1
Panel);W_D(Maker/Size:);W_D(HSD499
Panel);W_D(ID:);W_D(HSD050FHW3
Purpose:);W_D(CODE
Remark:);W_D(V2.0
Version:);W_D(
Date:);W_D(D:\PORJECT\F056\A4\翴獹龟喷\э\HSD499W3\RM68200GA1_HSD499_HSD050FHW3_CODE_V2.0_141222
**************************************************/

  // Set EXTC,
  GP_COMMAD_PA(0x04);
  W_D(0xB9);
  W_D(0xFF);
  W_D(0x83);
  W_D(0x89);
  //******************************** 3-Power Mode ******************************
  // VSP=5.5V; VSN=-5.5V; VDD1=1.8V
  // VGH=15.2V, VGL= -12V,
  // VSPR=5V, VSNR=-5V

  //HX8394-F_BOE_AN_V01.07_2015_1001.pdf P21
  // Set EXTC
  GP_COMMAD_PA(0x04);
  W_D(0xB9);
  W_D(0xFF);
  W_D(0x83);
  W_D(0x94);

  // Set Power
  GP_COMMAD_PA(0x0B);
  W_D(0xB1);
  W_D(0x48);
  W_D(0x12);
  W_D(0x72);
  W_D(0x09);
  W_D(0x33);
  W_D(0x54);
  W_D(0x51);
  W_D(0x51);
  W_D(0x30);
  W_D(0x43);

  //) Set MIPI
  GP_COMMAD_PA(0x07);
  W_D(0xBA);
  W_D(0x63);
  W_D(0x03);
  W_D(0x68);
  W_D(0x6B);
  W_D(0xB2);
  W_D(0xC0);

  //Set Display
  GP_COMMAD_PA(0x07);
  W_D(0xB2);
  W_D(0x00);
  W_D(0x80);
  W_D(0x64);
  W_D(0x0C);
  W_D(0x06);
  W_D(0x2F);

  // Set CYC
  GP_COMMAD_PA(0x1F);
  W_D(0xB4);
  W_D(0x76);
  W_D(0x74);
  W_D(0x76);
  W_D(0x74);
  W_D(0x76);
  W_D(0x74);
  W_D(0x01);
  W_D(0x05);
  W_D(0x84);
  W_D(0x35);
  W_D(0x00);
  W_D(0x3F);
  W_D(0x76);
  W_D(0x74);
  W_D(0x76);
  W_D(0x74);
  W_D(0x76);
  W_D(0x74);
  W_D(0x01);
  W_D(0x05);
  W_D(0x84);
  W_D(0x3F);
  W_D(0x00);
  W_D(0xFF);
  W_D(0x81);
  W_D(0x81);
  W_D(0x81);
  W_D(0x81);
  W_D(0x08);
  W_D(0x01);

  // Set);W_D(0xD3
  GP_COMMAD_PA(0x22);
  W_D(0xD3);
  W_D(0x00);
  W_D(0x00);
  W_D(0x0F);
  W_D(0x0F);
  W_D(0x00);
  W_D(0x00);
  W_D(0x12);
  W_D(0x10);
  W_D(0x32);
  W_D(0x10);
  W_D(0x00);
  W_D(0x00);
  W_D(0x00);
  W_D(0x32);
  W_D(0x13);
  W_D(0xC0);
  W_D(0x00);
  W_D(0x00);
  W_D(0x32);
  W_D(0x10);
  W_D(0x08);
  W_D(0x00);
  W_D(0x00);
  W_D(0x47);
  W_D(0x04);
  W_D(0x02);
  W_D(0x02);
  W_D(0x47);
  W_D(0x04);
  W_D(0x00);
  W_D(0x47);
  W_D(0x0C);
  W_D(0x40);

  // Set GIP
  GP_COMMAD_PA(0x2D);
  W_D(0xD5);
  W_D(0x00);
  W_D(0x01);
  W_D(0x02);
  W_D(0x03);
  W_D(0x04);
  W_D(0x05);
  W_D(0x06);
  W_D(0x07);
  W_D(0x20);
  W_D(0x21);
  W_D(0x22);
  W_D(0x23);
  W_D(0x18);
  W_D(0x18);
  W_D(0x18);
  W_D(0x18);
  W_D(0x18);
  W_D(0x18);
  W_D(0x18);
  W_D(0x18);
  W_D(0x18);
  W_D(0x18);
  W_D(0x18);
  W_D(0x18);
  W_D(0x18);
  W_D(0x18);
  W_D(0x18);
  W_D(0x18);
  W_D(0x18);
  W_D(0x18);
  W_D(0x18);
  W_D(0x18);
  W_D(0x18);
  W_D(0x18);
  W_D(0x18);
  W_D(0x18);
  W_D(0x18);
  W_D(0x18);
  W_D(0x18);
  W_D(0x18);
  W_D(0x19);
  W_D(0x19);
  W_D(0x18);
  W_D(0x18);

  // Set
  GP_COMMAD_PA(0x2D);
  W_D(0xD6);
  W_D(0x07);
  W_D(0x06);
  W_D(0x05);
  W_D(0x04);
  W_D(0x03);
  W_D(0x02);
  W_D(0x01);
  W_D(0x00);
  W_D(0x23);
  W_D(0x22);
  W_D(0x21);
  W_D(0x20);
  W_D(0x18);
  W_D(0x18);
  W_D(0x18);
  W_D(0x18);
  W_D(0x18);
  W_D(0x18);
  W_D(0x18);
  W_D(0x18);
  W_D(0x18);
  W_D(0x18);
  W_D(0x18);
  W_D(0x18);
  W_D(0x18);
  W_D(0x18);
  W_D(0x18);
  W_D(0x18);
  W_D(0x18);
  W_D(0x18);
  W_D(0x18);
  W_D(0x18);
  W_D(0x18);
  W_D(0x18);
  W_D(0x18);
  W_D(0x18);
  W_D(0x18);
  W_D(0x18);
  W_D(0x18);
  W_D(0x18);
  W_D(0x18);
  W_D(0x18);
  W_D(0x19);
  W_D(0x19);

  // Set VCOM
  GP_COMMAD_PA(0x03);
  W_D(0xB6);
  W_D(0x34);
  W_D(0x34);

  //Set Gamma
  GP_COMMAD_PA(0x3B);
  W_D(0xE0);
  W_D(0x00);
  W_D(0x06);
  W_D(0x13);
  W_D(0x18);
  W_D(0x1C);
  W_D(0x20);
  W_D(0x23);
  W_D(0x22);
  W_D(0x48);
  W_D(0x58);
  W_D(0x6A);
  W_D(0x6B);
  W_D(0x74);
  W_D(0x88);
  W_D(0x8E);
  W_D(0x94);
  W_D(0xA2);
  W_D(0xA6);
  W_D(0xA3);
  W_D(0xB2);
  W_D(0xC5);
  W_D(0x63);
  W_D(0x61);
  W_D(0x66);
  W_D(0x6C);
  W_D(0x6C);
  W_D(0x73);
  W_D(0x7F);
  W_D(0x7F);
  W_D(0x00);
  W_D(0x06);
  W_D(0x13);
  W_D(0x18);
  W_D(0x1C);
  W_D(0x20);
  W_D(0x23);
  W_D(0x22);
  W_D(0x48);
  W_D(0x58);
  W_D(0x6A);
  W_D(0x6B);
  W_D(0x75);
  W_D(0x89);
  W_D(0x8F);
  W_D(0x95);
  W_D(0xA3);
  W_D(0xA6);
  W_D(0xA3);
  W_D(0xB3);
  W_D(0xC5);
  W_D(0x63);
  W_D(0x62);
  W_D(0x67);
  W_D(0x6C);
  W_D(0x71);
  W_D(0x78);
  W_D(0x7F);
  W_D(0x7F);

  // Set Panel
  GP_COMMAD_PA(0x02);
  W_D(0xCC);
  W_D(0x03);

  // Set
  GP_COMMAD_PA(0x03);
  W_D(0xC0);
  W_D(0x1F);
  W_D(0x31);

  //Set
  GP_COMMAD_PA(0x02);
  W_D(0xD4);
  W_D(0x02);

  //Set
  GP_COMMAD_PA(0x02);
  W_D(0xBD);
  W_D(0x01);

  //Set GAS
  GP_COMMAD_PA(0x02);
  W_D(0xB1);
  W_D(0x60);

  //Set
  GP_COMMAD_PA(0x02);
  W_D(0xBD);
  W_D(0x00);

  //Set Power Option HX5186 Mode
  GP_COMMAD_PA(0x08);
  W_D(0xBF);
  W_D(0x40);
  W_D(0x81);
  W_D(0x50);
  W_D(0x00);
  W_D(0x1A);
  W_D(0xFC);
  W_D(0x01);


  GP_COMMAD_PA(0x02);
  W_D(0x36);
  W_D(0x02);



  // Sleep Out
  GP_COMMAD_PA(0x02);
  W_D(0x11);
  W_D(0x00);
  delay_ms(150);
  // Display On
  GP_COMMAD_PA(0x02);
  W_D(0x29);
  W_D(0x00);
  delay_ms(20);
  

  W_C(0xBC);
  W_D(0x00);
  W_D(0x00);

  //W_C(0xBF);
  W_C(0x11); //
  //W_D(0x00);     //
  delay_ms(100);

  W_C(0xBC);
  W_D(0x00);
  W_D(0x00);
  //W_C(0xBF);
  W_C(0x29); //  Display On
  delay_ms(200);

  /*==============================================================================================================================*/

  W_C(0xb7);
  W_D(0x50);
  W_D(0x00); //Configuration Register

  W_C(0xb8);
  W_D(0x00);
  W_D(0x00); //VC(Virtual ChannelID) Control Register

  W_C(0xb9);
  W_D(0x00); //1=PLL disable
  W_D(0x00);

  W_C(0xBA); //PLL=(TX_CLK/MS)*NS 8228=480M 4428=240M  061E=120M 4214=240M 821E=360M 8219=300M 8225=444M 8224=432
  W_D(0x28); //D7-0=NS(0x01 : NS=1)
  W_D(0x82); //D15-14=PLL范围 00=62.5-125 01=126-250 10=251-500 11=501-1000  DB12-8=MS(01:MS=1)

  W_C(0xBB); //LP Clock Divider LP clock = 400MHz / LPD / 8 = 480 / 8/ 8 = 7MHz
  W_D(0x07); //D5-0=LPD=0x1 – Divide by 2
  W_D(0x00);

  W_C(0xb9);
  W_D(0x01); //1=PLL disable
  W_D(0x00);

  W_C(0xc9);
  W_D(0x02);
  W_D(0x23); //p1: HS-Data-zero  p2: HS-Data- prepare  --> 8031 issue
  delay_ms(10);

  W_C(0xCA);
  W_D(0x01); //CLK Prepare
  W_D(0x23); //Clk Zero

  W_C(0xCB); //local_write_reg(addr=0xCB,data=0x0510)
  W_D(0x10); //Clk Post
  W_D(0x05); //Clk Per

  W_C(0xCC); //local_write_reg(addr=0xCC,data=0x100A)
  W_D(0x05); //HS Trail
  W_D(0x10); //Clk Trail

  W_C(0xD0);
  W_D(0x00);
  W_D(0x00);

  //RGB interface configuration
  W_C(0xB1);
  W_D(HSPW); //HSPW 07
  W_D(VSPW); //VSPW 05

  W_C(0xB2);
  W_D(HBPD); //HBPD 0x64=100
  W_D(VBPD); //VBPD 8 减小下移

  W_C(0xB3);
  W_D(HFPD); //HFPD 8
  W_D(VFPD); //VFPD 10

  W_C(0xB4); //Horizontal active period 720=02D0
  W_D(0xD0); //013F=319 02D0=720
  W_D(0x02);

  W_C(0xB5); //Vertical active period 1280=0500
  W_D(0x00); //01DF=479 0500=1280
  W_D(0x05);

  W_C(0xB6); //RGB CLK  16BPP=00 18BPP=01
  W_D(0x07); //D7=0 D6=0 D5=0  D1-0=11 – 24bpp
  W_D(0x20); //D15=VS D14=HS D13=CLK D12-9=NC D8=0=Video with blanking packet. 00-F0

  //MIPI lane configuration
  W_C(0xDE); //通道数
  W_D(0x03); //11=4LANE 10=3LANE 01=2LANE 00=1LANE
  W_D(0x00);

  W_C(0xD6); //  05=BGR  04=RGB
  W_D(0x05); //D0=0=RGB 1:BGR D1=1=Most significant byte sent first
  W_D(0x00);

  W_C(0xB7);
  W_D(0x4B);
  W_D(0x02);
}

/* USER CODE END 0 */

/**
  * @brief  The application entry point.
  * @retval int
  */
int main(void)
{
  /* USER CODE BEGIN 1 */

  /* USER CODE END 1 */

  /* MCU Configuration--------------------------------------------------------*/

  /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
  HAL_Init();

  /* USER CODE BEGIN Init */

  /* USER CODE END Init */

  /* Configure the system clock */
  SystemClock_Config();

  /* USER CODE BEGIN SysInit */

  /* USER CODE END SysInit */

  /* Initialize all configured peripherals */
  MX_GPIO_Init();
  MX_USART1_UART_Init();

  /* Initialize interrupts */
  MX_NVIC_Init();
  /* USER CODE BEGIN 2 */

  /* USER CODE END 2 */

  /* Infinite loop */
  /* USER CODE BEGIN WHILE */
  printf("Program Start\r\n");

  // test spi
  /*spi_init();
  while(1)
  {
    spi_write(SPI_CMD, 0xa5);
    HAL_Delay(10);
    spi_write(SPI_DAT, 0x5a);
    HAL_Delay(10);
  }*/

  spi_init();

  ssd2828_hwreset();

  /*ssd2828_writeReg(0xd4, 0x00, 0xfa);

  uint16_t ssd2828ID = ssd2828_readReg(0xb0);
  
  printf("read 2828 id = 0x%x\r\n", ssd2828ID);*/

  /*for(uint8_t i = 0xB0; i < 0xff; i++)
  {
    uint16_t regData = ssd2828_readReg(i);

    printf("reg(0x%02x) = 0x%04x \r\n", i, regData);
  }*/
  //readMipi()

  //Init_SSD2828(init_ST7703__BV055HDE_N47_3Q00);
  //Init_SSD2828(init_ST7703_BV055HDE_47_IPS_Code);
  init();

  while (1)
  {
    /* USER CODE END WHILE */

    /* USER CODE BEGIN 3 */
    /*HAL_GPIO_WritePin(LED_GPIO_Port, LED_Pin, GPIO_PIN_RESET);
    HAL_Delay(1000);
    HAL_GPIO_WritePin(LED_GPIO_Port, LED_Pin, GPIO_PIN_SET);
    HAL_Delay(1000);*/

    //uint8_t dat = 0xa5;
    //HAL_UART_Transmit(&huart1, &dat, 1, 100);
    //HAL_Delay(1000);

    //printf("hello stm32\r\n");
    //HAL_Delay(1000);

    /*HAL_GPIO_TogglePin(LCD_RST_GPIO_Port, LCD_RST_Pin);
    HAL_GPIO_TogglePin(LCD_CS_GPIO_Port, LCD_CS_Pin);
    HAL_GPIO_TogglePin(LCD_MOSI_GPIO_Port, LCD_MOSI_Pin);
    HAL_GPIO_TogglePin(LCD_SCK_GPIO_Port, LCD_SCK_Pin);
    HAL_Delay(1000);*/

    /*if(HAL_GPIO_ReadPin(LCD_MISO_GPIO_Port, LCD_MISO_Pin) == GPIO_PIN_SET) 
    {
      HAL_GPIO_WritePin(LED_GPIO_Port, LED_Pin, GPIO_PIN_SET);
    } else {
      HAL_GPIO_WritePin(LED_GPIO_Port, LED_Pin, GPIO_PIN_RESET);
    }
    HAL_Delay(200);*/

    printf("Loop...\r\n");
    HAL_Delay(1000);
  }
  /* USER CODE END 3 */
}

/**
  * @brief System Clock Configuration
  * @retval None
  */
void SystemClock_Config(void)
{
  RCC_OscInitTypeDef RCC_OscInitStruct = {0};
  RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};

  /** Initializes the CPU, AHB and APB busses clocks 
  */
  RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;
  RCC_OscInitStruct.HSIState = RCC_HSI_ON;
  RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;
  RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
  RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI_DIV2;
  RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL16;
  if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
  {
    Error_Handler();
  }
  /** Initializes the CPU, AHB and APB busses clocks 
  */
  RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2;
  RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
  RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
  RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2;
  RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;

  if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2) != HAL_OK)
  {
    Error_Handler();
  }
}

/**
  * @brief NVIC Configuration.
  * @retval None
  */
static void MX_NVIC_Init(void)
{
  /* USART1_IRQn interrupt configuration */
  HAL_NVIC_SetPriority(USART1_IRQn, 0, 0);
  HAL_NVIC_EnableIRQ(USART1_IRQn);
}

/**
  * @brief USART1 Initialization Function
  * @param None
  * @retval None
  */
static void MX_USART1_UART_Init(void)
{

  /* USER CODE BEGIN USART1_Init 0 */

  /* USER CODE END USART1_Init 0 */

  /* USER CODE BEGIN USART1_Init 1 */

  /* USER CODE END USART1_Init 1 */
  huart1.Instance = USART1;
  huart1.Init.BaudRate = 115200;
  huart1.Init.WordLength = UART_WORDLENGTH_8B;
  huart1.Init.StopBits = UART_STOPBITS_1;
  huart1.Init.Parity = UART_PARITY_NONE;
  huart1.Init.Mode = UART_MODE_TX_RX;
  huart1.Init.HwFlowCtl = UART_HWCONTROL_NONE;
  huart1.Init.OverSampling = UART_OVERSAMPLING_16;
  if (HAL_UART_Init(&huart1) != HAL_OK)
  {
    Error_Handler();
  }
  /* USER CODE BEGIN USART1_Init 2 */

  /* USER CODE END USART1_Init 2 */
}

/**
  * @brief GPIO Initialization Function
  * @param None
  * @retval None
  */
static void MX_GPIO_Init(void)
{
  GPIO_InitTypeDef GPIO_InitStruct = {0};

  /* GPIO Ports Clock Enable */
  __HAL_RCC_GPIOC_CLK_ENABLE();
  __HAL_RCC_GPIOA_CLK_ENABLE();
  __HAL_RCC_GPIOB_CLK_ENABLE();

  /*Configure GPIO pin Output Level */
  HAL_GPIO_WritePin(LED_GPIO_Port, LED_Pin, GPIO_PIN_RESET);

  /*Configure GPIO pin Output Level */
  HAL_GPIO_WritePin(GPIOA, LCD_RST_Pin | LCD_CS_Pin | LCD_SCK_Pin | LCD_MOSI_Pin, GPIO_PIN_RESET);

  /*Configure GPIO pin Output Level */
  HAL_GPIO_WritePin(GPIOB, SHUT_Pin | U_CON_Pin, GPIO_PIN_RESET);

  /*Configure GPIO pin : LED_Pin */
  GPIO_InitStruct.Pin = LED_Pin;
  GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  GPIO_InitStruct.Pull = GPIO_NOPULL;
  GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  HAL_GPIO_Init(LED_GPIO_Port, &GPIO_InitStruct);

  /*Configure GPIO pins : LCD_RST_Pin LCD_CS_Pin LCD_SCK_Pin LCD_MOSI_Pin */
  GPIO_InitStruct.Pin = LCD_RST_Pin | LCD_CS_Pin | LCD_SCK_Pin | LCD_MOSI_Pin;
  GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  GPIO_InitStruct.Pull = GPIO_NOPULL;
  GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);

  /*Configure GPIO pin : LCD_MISO_Pin */
  GPIO_InitStruct.Pin = LCD_MISO_Pin;
  GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
  GPIO_InitStruct.Pull = GPIO_NOPULL;
  HAL_GPIO_Init(LCD_MISO_GPIO_Port, &GPIO_InitStruct);

  /*Configure GPIO pins : SHUT_Pin U_CON_Pin */
  GPIO_InitStruct.Pin = SHUT_Pin | U_CON_Pin;
  GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  GPIO_InitStruct.Pull = GPIO_NOPULL;
  GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
}

/* USER CODE BEGIN 4 */

/* USER CODE END 4 */

/**
  * @brief  This function is executed in case of error occurrence.
  * @retval None
  */
void Error_Handler(void)
{
  /* USER CODE BEGIN Error_Handler_Debug */
  /* User can add his own implementation to report the HAL error return state */

  /* USER CODE END Error_Handler_Debug */
}

#ifdef USE_FULL_ASSERT
/**
  * @brief  Reports the name of the source file and the source line number
  *         where the assert_param error has occurred.
  * @param  file: pointer to the source file name
  * @param  line: assert_param error line source number
  * @retval None
  */
void assert_failed(uint8_t *file, uint32_t line)
{
  /* USER CODE BEGIN 6 */
  /* User can add his own implementation to report the file name and line number,
     tex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
  /* USER CODE END 6 */
}
#endif /* USE_FULL_ASSERT */

/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
